﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#pragma warning disable 1591
namespace Tab2Sql.GarbageIn
{
    public class Address
    {

        public Address(string unknownInput,int lastID)
        {
            Full_Address = unknownInput;
            string pc = DGen.DText.GetPostCode(unknownInput);
            if (pc.Length > 0) { Post_Code = pc; }
            string ps = DGen.DText.GetPostStub(unknownInput);
            if (ps.Length > 0) { Post_Stub = ps; }
            if (unknownInput.Contains(","))
            {
                Add_1 = DGen.DText.LeftOf(unknownInput, ",");
                Add_1 = Add_1.TrimEnd(new char[]{','});
            }
            else { Add_1 = unknownInput; }
            Add_1_Six = Add_1.ToUpper().Replace(" ", "");
            Add_1_Six = DGen.DText.Left(Add_1_Six, 6);
            Add_1_Ten = DGen.DText.Left(unknownInput, 10).Trim().TrimEnd(new char[]{','});
            Add_1_Fifteen = DGen.DText.Left(unknownInput, 15).Trim().TrimEnd(new char[] { ',' });

            District = DGen.DText.GetDistrict(unknownInput).ToUpper();
            Full_Address = unknownInput;
            Full_Address2 = unknownInput;
            Stub = DGen.DText.JustLetters(Full_Address).Split(' ')[0];
            string door = DGen.DText.JustNumbers(DGen.DText.Left(unknownInput, 15));
            bool m = Int32.TryParse(door, out Door);
            if (!m) { Door = 0; }

            ID = lastID + 1;
        }
        public Address(string add1,string add2,string add3,string postcode,string poststub,int door,string doorsuffix,string uprn,int locode,int lastID)
        {
            Lo_Code = locode;
            UPRN = uprn;
            Add_1 = add1;
            Add_2 = add2;
            Add_3 = add3;
            Post_Code = postcode;
            Post_Stub = poststub;
            Door = door;
            Door_Suffix = doorsuffix;
            ID = lastID + 1;
        }
        public Address(string add1, string uprn, int locode)
        {
            Lo_Code = locode;
            UPRN = uprn;
            Add_1 = add1;
            ID = -1;
        }
        public Address(string add1, string add2,string add3,string district,string postcode,string poststub,string door,string doorsuffix,string uprn, string locode,string fulladdress,int lastID)
        {
            
            UPRN = uprn;
            Add_1 = add1;
            Add_1_Ten = DGen.DText.Left(Add_1, 10);
            Add_1_Six = Add_1.ToUpper().Replace(" ", "");
            Add_1_Six = DGen.DText.Left(Add_1_Six, 6);
            Add_1_Fifteen = DGen.DText.Left(Add_1, 15);
            Add_2 = add2;
            Add_3 = add3;
            Post_Code = postcode;
            Post_Stub = poststub;
            District = district.ToUpper();
            Full_Address = fulladdress;
            Full_Address2 = fulladdress;
            bool m = Int32.TryParse(door,out Door);
            if (!m) { Door = 0; }
            bool m2 = Int32.TryParse(locode, out Lo_Code);
            if (!m2) { Lo_Code = 0; }
            Door_Suffix = doorsuffix;
            ID = lastID++;

            Stub = DGen.DText.JustLetters(Full_Address).Split(' ')[0];
          


        }
        public Address()
        {
        }


        public int ID;
        public int Lo_Code;
        public int Door;
        public string Street;
        public string Door_Suffix;
        public string UPRN;
        public string Add_1;
        public string Add_1_Six;
        public string Add_1_Ten;
        public string Add_1_Fifteen;
        public string Add_2;
        public string Add_3;
        public string District;
        public string Post_Code;
        public string Post_Stub;
        public string Full_Address;
        public string Full_Address2;
        public string Stub;
    }
}
#pragma warning restore 1591